
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 09/05/2013 22:22:01
-- Generated from EDMX file: d:\losezhang\学习陈晴阳的DDD_AOP_WCF\DDD_AOP_WCF.Domain\Background.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [background];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Order_Detail_Order_Info]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Order_Detail] DROP CONSTRAINT [FK_Order_Detail_Order_Info];
GO
IF OBJECT_ID(N'[dbo].[FK_Product_User_Info]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Product] DROP CONSTRAINT [FK_Product_User_Info];
GO
IF OBJECT_ID(N'[dbo].[FK_ProductDetail_Product]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProductDetail] DROP CONSTRAINT [FK_ProductDetail_Product];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Category]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Category];
GO
IF OBJECT_ID(N'[dbo].[Order_Detail]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Order_Detail];
GO
IF OBJECT_ID(N'[dbo].[Order_Info]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Order_Info];
GO
IF OBJECT_ID(N'[dbo].[Product]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Product];
GO
IF OBJECT_ID(N'[dbo].[ProductDetail]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProductDetail];
GO
IF OBJECT_ID(N'[dbo].[User_Info]', 'U') IS NOT NULL
    DROP TABLE [dbo].[User_Info];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Category'
CREATE TABLE [dbo].[Category] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [ParentID] int  NULL,
    [Level] int  NOT NULL,
    [Name] nvarchar(50)  NULL,
    [IsParent] bit  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [Sortable] int  NOT NULL
);
GO

-- Creating table 'Order_Detail'
CREATE TABLE [dbo].[Order_Detail] (
    [OrderDetailID] int IDENTITY(1,1) NOT NULL,
    [OrderID] int  NOT NULL,
    [ProductID] int  NOT NULL,
    [ProductName] varchar(50)  NULL
);
GO

-- Creating table 'Order_Info'
CREATE TABLE [dbo].[Order_Info] (
    [OrderID] int IDENTITY(1,1) NOT NULL,
    [UserID] int  NOT NULL,
    [CreateDate] datetime  NOT NULL
);
GO

-- Creating table 'ProductDetail'
CREATE TABLE [dbo].[ProductDetail] (
    [ProductDetailID] int IDENTITY(1,1) NOT NULL,
    [ProductID] int  NOT NULL,
    [ExtensionInfo] nvarchar(max)  NULL
);
GO

-- Creating table 'User_Info'
CREATE TABLE [dbo].[User_Info] (
    [UserID] int IDENTITY(1,1) NOT NULL,
    [UserName] varchar(50)  NULL,
    [RealName] varchar(50)  NULL,
    [ProductCount] int  NOT NULL,
    [Email] nvarchar(255)  NULL,
    [OrderCount] int  NOT NULL,
    [Phone] varchar(50)  NULL,
    [Address] nvarchar(512)  NULL,
    [CreateDate] datetime  NOT NULL,
    [UpdateDate] datetime  NOT NULL,
    [Status] int  NOT NULL
);
GO

-- Creating table 'Product'
CREATE TABLE [dbo].[Product] (
    [ProductID] int IDENTITY(1,1) NOT NULL,
    [ProductName] varchar(50)  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [SaleCount] int  NOT NULL,
    [ClickCount] int  NULL,
    [Info] varchar(50)  NOT NULL,
    [UserID] int  NOT NULL,
    [SalePrice] decimal(18,0)  NOT NULL,
    [Discount] int  NOT NULL,
    [UpdateDate] datetime  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Category'
ALTER TABLE [dbo].[Category]
ADD CONSTRAINT [PK_Category]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [OrderDetailID] in table 'Order_Detail'
ALTER TABLE [dbo].[Order_Detail]
ADD CONSTRAINT [PK_Order_Detail]
    PRIMARY KEY CLUSTERED ([OrderDetailID] ASC);
GO

-- Creating primary key on [OrderID] in table 'Order_Info'
ALTER TABLE [dbo].[Order_Info]
ADD CONSTRAINT [PK_Order_Info]
    PRIMARY KEY CLUSTERED ([OrderID] ASC);
GO

-- Creating primary key on [ProductDetailID] in table 'ProductDetail'
ALTER TABLE [dbo].[ProductDetail]
ADD CONSTRAINT [PK_ProductDetail]
    PRIMARY KEY CLUSTERED ([ProductDetailID] ASC);
GO

-- Creating primary key on [UserID] in table 'User_Info'
ALTER TABLE [dbo].[User_Info]
ADD CONSTRAINT [PK_User_Info]
    PRIMARY KEY CLUSTERED ([UserID] ASC);
GO

-- Creating primary key on [ProductID] in table 'Product'
ALTER TABLE [dbo].[Product]
ADD CONSTRAINT [PK_Product]
    PRIMARY KEY CLUSTERED ([ProductID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [OrderID] in table 'Order_Detail'
ALTER TABLE [dbo].[Order_Detail]
ADD CONSTRAINT [FK_Order_Detail_Order_Info]
    FOREIGN KEY ([OrderID])
    REFERENCES [dbo].[Order_Info]
        ([OrderID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Order_Detail_Order_Info'
CREATE INDEX [IX_FK_Order_Detail_Order_Info]
ON [dbo].[Order_Detail]
    ([OrderID]);
GO

-- Creating foreign key on [UserID] in table 'Product'
ALTER TABLE [dbo].[Product]
ADD CONSTRAINT [FK_Product_User_Info]
    FOREIGN KEY ([UserID])
    REFERENCES [dbo].[User_Info]
        ([UserID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Product_User_Info'
CREATE INDEX [IX_FK_Product_User_Info]
ON [dbo].[Product]
    ([UserID]);
GO

-- Creating foreign key on [ProductID] in table 'ProductDetail'
ALTER TABLE [dbo].[ProductDetail]
ADD CONSTRAINT [FK_ProductDetail_Product]
    FOREIGN KEY ([ProductID])
    REFERENCES [dbo].[Product]
        ([ProductID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProductDetail_Product'
CREATE INDEX [IX_FK_ProductDetail_Product]
ON [dbo].[ProductDetail]
    ([ProductID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------